<?php

namespace App\Admin\Controllers;

use Carbon\Carbon;
use Encore\Admin\Grid;
use App\Models\GoldChild;
use Encore\Admin\Controllers\AdminController;

class GoldChildrenController extends AdminController
{
    protected $title = '金店下级团队';
    
    protected function grid()
    {
        $grid = new Grid(new GoldChild());
        $grid->model()->whereDate('created_at', Carbon::today())->orderByDesc('more_than_first_day');

        $grid->column('id', 'ID');
        $grid->column('user_id', '会员')->display(function () {
	        return $this->user->nameText(true);
        });
        $grid->column('records_children_count', '下级人数');
        $grid->column('more_than_last_day', '较昨日新增');
        $grid->column('more_than_first_day', '较首日新增');
        $grid->column('created_at', '创建')->display(function () {
        	return $this->created_at->toDateString();
        });
	
	    $grid->disableRowSelector();
	    $grid->disableExport();
	    $grid->disableCreateButton();
	    $grid->disableActions();
	    $this->gridFilter($grid);

        return $grid;
    }
	
	protected function gridActions(Grid $grid)
	{
		$grid->actions(function (Grid\Displayers\Actions $actions) {
			$actions->disableView();
			$actions->disableDelete();
		});
	}
	
	protected function gridFilter(Grid $grid)
	{
		$grid->filter(function (Grid\Filter $filter) {
			$filter->expand();
			
			$filter->column(1/2, function (Grid\Filter $filter) {
				$filter->disableIdFilter();
				$filter->equal('user_id', '会员');
				$filter->date('created_at', '日期');
			});
		});
	}
}
